#pragma once

#include "CPacketSender.h"
#include "CPacketReceiver.h"
#include "C2DGraphics.h"
#include "Dialogs.h"

#define MAX_DIALOGS 20     //arbitrary maximum number of open dialogs

//User preferences that are persisted
typedef struct PrefStruct
{
	char LoginID[32];
	char Password[32];
	char Callsign[32];
	char ICAOType[32];
	long PTTVKey;
	long PTTJoyButton;
} PrefStruct;

typedef class CFSXGUI
{
public:
	CFSXGUI();
	~CFSXGUI();

	//////////////////
	//Called by GUI-FSX functions from FSX
	void Initialize();
	void Shutdown();
	void OnFSXPresent(IDirect3DDevice9 *pI);
	void OnFSXSimRunning();
	void OnFSXSimStopped();
	void OnFSXAddonMenuSelected();

	LRESULT ProcessFSXWindowMessage(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);

	//////////////////
	//Called by dialogs

	//Add dialog to the open dialog list, at top-most spot
	void AddDialog(CDialog *pDialog);

	//Remove dialog from the open dialog list
	void RemoveDialog(CDialog *pDialog);

	//Move given already-added dialog to the top-most spot 
	void SetTopmostDialog(CDialog *pDialog);

	//Indicate some dialog needs mouse move messages (true) or no longer (false)
	void IndicateNeedMouseMove(bool bNeedMouseMove);

	//Indicate some dialog needs keyboard keys (true) or no longer (false)
	void IndicateNeedKeyboard(bool bNeedKeyboard);


	C2DGraphics m_Graphics;

protected:
	HWND        m_hFSXWindow;
	bool		m_bGraphicsInitialized; 
	bool		m_bRunning;				//True if we're running (some dialog is showing) 
	bool        m_bNeedMouseMove;       //True if we should forward mouse move messages to the dialogs (e.g. dragging some dialog)
	bool		m_bNeedKeyboard;        //True if we should forward keystrokes to the dialogs (e.g. edit box is active)
	PrefStruct  m_Prefs;                //User preferences
	LONG_PTR	m_FSXWindowProc;        //FSX's main windows procedure

	//Dialogs
	CLoginDlg		m_dlgLogin;
	CMainDlg		m_dlgMain;
	CChatDlg		m_dlgChat;
	COptionsDlg		m_dlgOptions;
	CFlightPlanDlg	m_dlgFlightPlan;

	//Dialog list for drawing and windows message order
	CDialog*	m_aOpenDialogs[MAX_DIALOGS];  //open dialogs, spot 0 is topmost (drawn bottom-up, messages sent top-down)
	int			m_iNumOpenDialogs;
	
	void InitGraphics(IDirect3DDevice9 *pI);

	//PTT pressed or released
	void OnPTTButton(bool bPressed);

} CFSXGUI;


